require(['./config'],() => {
    require(['template','request','header','jquery'],(template,req) =>{
        class Register{
            constructor(){
                // this.init();
                this.options = {};
                this.getData();
            }
            init(){
                
            }
            getData(){
                console.log($('.subBtn'));
                $('.subBtn').click(() => {
                    //获取用户输入的信息
                    var username = $('.username').val();
                    var email = $('.email').val();
                    var pwd = $('.pwd').val();
                    var repwd = $('.repwd').val();

                    //判断localStorage中有没有这条数据 
                    var userArr = localStorage.getItem('userArr');
                    // console.log(userArr)
                    if(userArr){
                        //localStorage 里面有这条数据
                        //先转为数组再遍历
                        userArr = JSON.parse(userArr);
                        //判断userArr里面有没有这条数据
                        var flag = userArr.some((item,index) => {
                            return item.username === username;
                        })
                        // console.log(flag);
                        if(flag){
                            //代表里面有这条数据
                            alert('此账号已注册，请直接登录');
                        }else{
                            userArr.push({username,email,pwd,repwd});
                            alert("注册成功");
                            window.location.href="/html/login.html";
                        }
                        localStorage.setItem('userArr',JSON.stringify(userArr));
                    }else{
                        localStorage.setItem('userArr',JSON.stringify([{username,email,pwd,repwd}]));
                    }

                })
            }
        }
        return new Register();
    })
})
   